package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.OperationRecordMapper;
import com.net.xpay.common.domain.OperationRecord;
import com.net.xpay.common.manager.OperationRecordManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.model.search.OperationRecordSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ReadTransactional
public class OperationRecordManagerImpl extends AbstractManager<OperationRecord> implements OperationRecordManager{

    @Autowired
    private OperationRecordMapper mapper;


    @Override
    protected BasicMapper<Long, OperationRecord> getMapper() {
        return mapper;
    }

    @Override
    public List<OperationRecord> search(OperationRecordSearchModel searchModel) {
        // 预判空处理
        Preconditions.checkArgument(searchModel != null);
        // 封装查询条件
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel,page));
    }

    @Override
    public long searchCount(OperationRecordSearchModel searchModel) {
        // 预判空处理
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<OperationRecord> searchAll() {

        return mapper.searchAll();
    }
}
